var t = getApp(), a = require("../../0BACB9C3A71FB5DF6DCAD1C4BE4CA4D1.js"), e = require("../../A4730AC3A71FB5DFC21562C4223CA4D1.js");

Page({
    data: {
        isShowMenu: !1,
        orderType: 0,
        titleName: "全部订单",
        isLoading: !1,
        orders: [],
        page: 1,
        orderTypeList: {
            0: "全部",
            1: "待付款",
            2: "待发货",
            3: "待收货",
            4: "待取货",
            5: "已完成",
            6: "售后"
        },
        orderStatus: {
            0: "待支付",
            1: "支付中",
            2: "已支付",
            3: "已发货",
            4: "已完成",
            5: "取消订单",
            6: "退款"
        },
        statusBarHeight: t.globalData.statusBarHeight,
        titleBarHeight: t.globalData.titleBarHeight,
        navigationBarHeight: t.globalData.titleBarHeight + t.globalData.statusBarHeight,
        screenHeight: t.globalData.screenHeight,
        winWidth: t.globalData.windowWidth,
        getDataCount: 0,
        isShowCustomer: !1,
        total: 0,
        menuAnimData: {}
    },
    onShow: function() {
        this.data.orders.length ? 1 === this.data.getDataCount && t.globalData.isEditOrder && (t.globalData.isEditOrder = !1, 
        this.fetchData(1)) : this.fetchData(1, !0);
    },
    onReady: function() {
        this.menuAnim = wx.createAnimation({
            duration: 100
        }), this.payTip = this.selectComponent("#payTip");
    },
    onPullDownRefresh: function() {
        this.fetchData(1);
    },
    onReachBottom: function() {
        this.fetchData(this.data.page + 1);
    },
    tapOrderCell: function(t) {
        var a = 1 * t.currentTarget.dataset.orderStatusCustomer, e = 1 * t.currentTarget.dataset.orderStatus, i = t.currentTarget.dataset.orderId;
        1 === a && e <= 4 ? this.showCustomerModal() : wx.navigateTo({
            url: "/pages/order/detail?orderId=" + i
        });
    },
    tapPay: function(t) {
        var a = t.currentTarget.dataset.orderId, e = 1 * t.currentTarget.dataset.price;
        1 * t.currentTarget.dataset.type == 0 ? this.payTip.getDeviceMsg({
            orderId: a,
            price: e
        }) : wx.navigateTo({
            url: "/pages/pay/pay?orderId=" + a + "&price=" + e
        });
    },
    tapCallSend: function() {
        setTimeout(function() {
            wx.showToast({
                title: "已提醒商家发货",
                icon: "none"
            });
        }, 500);
    },
    tapLogistics: function(t) {
        var a = t.currentTarget.dataset.orderId;
        wx.navigateTo({
            url: "/pages/order/logistics?orderId=" + a
        });
    },
    tapReceiving: function(t) {
        var e = this;
        a.completeOrder(t.currentTarget.dataset.orderId, function() {
            e.fetchData(1);
        });
    },
    tapToExit: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    tapTitle: function() {
        var t = this, a = !this.data.isShowMenu;
        this.setData({
            isShowMenu: a
        }, function() {
            t.handleMenuAnim(a);
        });
    },
    tapCloseMenu: function() {
        var t = this;
        this.setData({
            isShowMenu: !1
        }, function() {
            t.handleMenuAnim(!1);
        });
    },
    handleMenuAnim: function(t) {
        var a = this.data.navigationBarHeight;
        t || (a = -this.data.winWidth / 750 * 568), this.menuAnim.top(a).step(), this.setData({
            menuAnimData: this.menuAnim.export()
        });
    },
    tapOrderType: function(t) {
        var a = this, e = t.currentTarget.dataset.type;
        this.setData({
            orderType: 1 * e,
            titleName: this.data.orderTypeList[e],
            isShowMenu: !1
        }, function() {
            a.handleMenuAnim(!1), a.fetchData(1);
        });
    },
    fetchData: function(t, a) {
        var i = this;
        this.data.isLoading ? wx.stopPullDownRefresh() : (a && wx.showLoading({
            title: "加载中...",
            mask: !0
        }), this.setData({
            isLoading: !0
        }), e.get("/v2/order/product/mine", {
            type: this.data.orderType,
            page: t || 1
        }).then(function(e) {
            if (a && wx.hideLoading(), wx.stopPullDownRefresh(), i.setData({
                isLoading: !1,
                getDataCount: 1
            }), 1001 === e.data.code) {
                var o = e.data.response.data, n = i.data.orders;
                n = 1 === (t = t || 1) ? o : n.concat(o), i.setData({
                    orders: n,
                    page: o.length > 0 ? t : t - 1,
                    total: e.data.response.total
                });
            }
        }).catch(function() {
            a && wx.hideLoading(), i.setData({
                isLoading: !1,
                getDataCount: 1
            }), wx.stopPullDownRefresh();
        }));
    },
    showCustomerModal: function() {
        this.setData({
            isShowCustomer: !0
        });
    },
    closeCustomerModal: function() {
        this.setData({
            isShowCustomer: !1
        });
    },
    saveQrcode: function() {
        var t = this;
        wx.saveImageToPhotosAlbum({
            filePath: "../../assets/images/customer_qrcode.png",
            complete: function() {
                t.closeCustomerModal();
            }
        });
    }
});